﻿#region license
// Copyright (c) 2010 Mauricio Scheffer
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//      http://www.apache.org/licenses/LICENSE-2.0
//  
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

using System;
using System.Web;
using System.Web.Security;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

namespace ProviderInjection {
    public class Global : HttpApplication, IContainerAccessor {
        private static IWindsorContainer container;

        private void Application_Start(object sender, EventArgs e) {
            container = new WindsorContainer();
            container.Register(Component.For<IUserRepository>().ImplementedBy<InMemoryUserRepository>());
            container.Register(Component.For<MyMembershipProvider>()
                .LifeStyle.Transient
                .Named("myProvider"));
        }

        private void Application_End(object sender, EventArgs e) {
            //  Code that runs on application shutdown
        }

        private void Application_Error(object sender, EventArgs e) {
            // Code that runs when an unhandled error occurs
        }

        private void Session_Start(object sender, EventArgs e) {
            // Code that runs when a new session is started
        }

        private void Session_End(object sender, EventArgs e) {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.
        }

        public IWindsorContainer Container {
            get { return container; }
        }
    }
}